package com.umfwechat.h5.controller.settlement;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.aspectj.org.eclipse.jdt.internal.compiler.lookup.InferenceContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.umfwechat.common.code.RetCode;
import com.umfwechat.common.constant.CacheConsts;
import com.umfwechat.h5.vo.SettleList;
import com.umfwechat.util.DesUtil;
import com.umfwechat.util.PropertyUtil;
import com.umfwechat.util.RandomUtil;
import com.umfwechat.util.RedisUtil;
import com.umfwechat.util.ReqMessageUtil;
import com.umfwechat.util.SaasPropertyUtil;
import com.umfwechat.util.SmsCheckUtil;
import com.umfwechat.util.StringUtil;
import com.umfwechat.wx.service.WeixinService;
import com.umpay.operation.model.edrawInf.EdrawInf;
import com.umpay.operation.service.edrawInf.remote.EdrawInfServiceRemote;
import com.umpay.sp.model.common.ReqMessage;
import com.umpay.sp.model.common.ResMessage;
import com.umpay.sp.model.revpay.RevPayOrder;
import com.umpay.sp.model.saas.StoreInf;
import com.umpay.sp.model.settle.SettleStat;
import com.umpay.sp.service.revpaynew.remote.RevPayOrderServiceRemote;
import com.umpay.sp.service.saas.remote.AppChannelServiceRemote;
import com.umpay.sp.service.saas.remote.StoreInfServiceRemote;
import com.umpay.sp.service.settle.remote.SettleStatServiceRemote;
import com.umpay.sp.util.AmountUtil;
import com.umpay.spapply.util.DateTimesUtil;
import com.umpay.util.HttpUtil;


/**
 * 收入结算
 * 
 * @author css
 * 
 */
@Controller
@RequestMapping("/h5/settlementController")
public class SettlementController {

	private static Logger logger = LoggerFactory.getLogger(SettlementController.class);

	// 查询店铺部署详情列表接口
	@Resource
	private StoreInfServiceRemote storeInfServiceRemote;
	
	//查询银行账户信息的接口
	@Resource
	private EdrawInfServiceRemote edrawInfRemote;

	//结算查询接口
	@Resource
	private SettleStatServiceRemote settleStatServiceRemote;
	
	//付款查询（提现）
	@Resource
	private RevPayOrderServiceRemote revPayOrderServiceRemote;
	
	//调用微信接口
	@Resource
	private WeixinService weixinService;
	
	//redis缓存时间，一天
	private int seconds = 24 * 60 * 60;
	

	/**
	 * 查询收款人信息（添加银行卡）
	 * @param request
	 * @param response
	 * @return
	 */
	@RequestMapping(value="/queryPayee",produces="text/html;charset=UTF-8")
	@ResponseBody
	public String queryPayee(HttpServletRequest request,HttpServletResponse response){
		logger.info("添加银行卡页面查询收款人信息接口");
		HttpSession session = request.getSession();
		Map<String , Object> resultMap = new HashMap<String ,Object>();
		if(session == null || session.getAttribute("merId").equals("")){
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取session信息失败!");
			logger.info("获取session信息失败!");
			return JSONObject.fromObject(resultMap).toString();
		}
		try {
			ReqMessage req = ReqMessageUtil.makeSpReq();
			String merId = StringUtil.trim(request.getSession().getAttribute("merId").toString());
			req.getReqMap().put("storeId", merId);
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~店铺部署详情信息接口，查询收款人信息~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			logger.info("店铺部署详情信息接口入参：" + req);
			ResMessage res = storeInfServiceRemote.getStoreInfByPri(req);
			logger.info("店铺部署详情信息接口出参：" + res);
			if(!res.getRetCode().equals(RetCode.SUCCESS)){	//查询失败
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "查询收款人信息接口失败!");
				logger.info("查询收款人信息失败merId："+merId);
				return JSONObject.fromObject(resultMap).toString();
			}
			com.umpay.sp.model.saas.StoreInf storeInfoo =  (com.umpay.sp.model.saas.StoreInf) res.getResMap().get("storeInf");
			if(storeInfoo ==null ||storeInfoo.equals("")){		//无数据
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "查询收款人信息无数据!");
				logger.info("查询收款人信息无数据merId："+merId);
				return JSONObject.fromObject(resultMap).toString();
			}
			String payeeInidcardSs = storeInfoo.getPayeeInidcard();  //查出的收款人身份证号是密文
			if(payeeInidcardSs == null || payeeInidcardSs.equals("")){	//校验身份证号码
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "收款人身份证号码为空!");
				logger.info("查询收款人信息身份证号码为空！merId："+merId);
				return JSONObject.fromObject(resultMap).toString();
			}
			String desKey = StringUtil.trim(PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties", "des.secureKey","KSagZxG3"));
			DesUtil desUtil = new DesUtil(desKey);
			String payeeInidcard = desUtil.dec_des(payeeInidcardSs);   //解密
			String  a= payeeInidcard.replaceAll("(\\d{6})\\d{8}(\\w{4})","$1******$2");//脱敏
			session.setAttribute("payeeName", storeInfoo.getPayeeName());	//收款人姓名放session中
			session.setAttribute("payeeInidcard",payeeInidcardSs);	//收款人身份证号放session中
			resultMap.put("retCode", RetCode.SUCCESS);
			resultMap.put("retMsg", "查询收款人信息成功!");
			logger.info("查询收款人信息成功！merId："+merId + storeInfoo);
			Map<String,Object> resM = new HashMap<String , Object>();
			resM.put("payeeName", storeInfoo.getPayeeName());
			resM.put("payeeInidcard",a);
			resM.put("payeeMobileId",storeInfoo.getPayeeMobileId());
			resultMap.put("storeInf", resM);
			return JSONObject.fromObject(resultMap).toString();
		} catch (Exception e) {
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "查询收款人信息失败!");
			logger.info("查询收款人信息失败！");
		} 
		return JSONObject.fromObject(resultMap).toString();
	}
	
	/**
	 * 添加银行卡页面，校验银行卡正确性
	 * @param request
	 * @param reponse
	 * @param bankAccount
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping(value="/checkCard",produces="text/html;charset=UTF-8")
	@ResponseBody
	public String checkCard(HttpServletRequest request ,HttpServletResponse response ,String bankAccount ){
		logger.info("添加银行卡页面校验银行卡接口");
		Map<String , Object> resultMap = new HashMap<String ,Object>();
		try {
			ReqMessage req = ReqMessageUtil.makeSpReq();
			Map<String,String>  reqMap = new HashMap<String, String>();
			reqMap.put("bankAccount", bankAccount);
			req.setReqMap(reqMap);
			//校验卡号是否为空
			if(reqMap.get("bankAccount") != null && !reqMap.get("bankAccount").equals("")){
				//~~~~~~~~~~~~~~~~~~~~~~~~~~~~调用卡bin信息接口，校验银行卡时候正确~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				logger.info("调用卡bin信息查询接口");
				String url = PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties","bin.qr.url");
				Map<String, Object> params  = new HashMap<String, Object>();
				ReqMessage r = ReqMessageUtil.makeSpReq();
				String rpid = r.getRpid();
				params.put("rpid",rpid);
				params.put("bankId", "00033000");
				params.put("cardId", bankAccount);
				logger.info("卡bin信息查询接口入参：" + params);
				Map<String, Object> a = HttpUtil.httpPostXStream2XStream(url, params,"utf-8");
				logger.info("卡bin信息查询接口出参：" + a);
				if(a == null || a.equals("")){		//查询失败
					resultMap.put("retCode", RetCode.FAIL);
					resultMap.put("retMsg", "调用卡bin失败!");
					logger.info("调用卡bin失败!");
					return JSONObject.fromObject(resultMap).toString();
				}
				if( !a.get("retCode").equals(RetCode.SUCCESS )){
					resultMap.put("retCode", a.get("retCode").toString());
					resultMap.put("retMsg", a.get("retMsg").toString());
					logger.info("调用卡bin失败!");
					return JSONObject.fromObject(resultMap).toString();
				}
				//校验银行卡类型（0储蓄卡）
				if( a.get("bankCardType") != null && !a.get("bankCardType").toString().equals("0")){
					resultMap.put("retCode", RetCode.FAIL);
					resultMap.put("retMsg", "只能绑定收款人名下的储蓄卡!");	
					return JSONObject.fromObject(resultMap).toString();
				}
				resultMap.put("retCode", RetCode.SUCCESS);
				resultMap.put("retMsg", "检验银行卡成功!");
				resultMap.put("binBankId", a.get("binBankId"));		//服务商Id
				resultMap.put("binBankName", a.get("binBankName"));	//银行卡服务商名称
				resultMap.put("bankCardType", a.get("bankCardType"));  //0为借记卡
				logger.info("检验银行卡成功!");
				return JSONObject.fromObject(resultMap).toString();
			}
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取银行卡号失败!");
			logger.info("获取银行卡号失败!");
			return JSONObject.fromObject(resultMap).toString();
		} catch (Exception e) {
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "校验银行卡失败!");
			logger.info("校验银行卡失败!");
		} 
		return JSONObject.fromObject(resultMap).toString();
	}
	
	
	/**
	 * 结算信息页面商户绑定银行卡信息接口
	 * @param request
	 * @param reponse
	 * @return
	 */
	@RequestMapping(value="/queryEdrewInfByMerId",produces="text/html;charset=UTF-8")
	@ResponseBody
	public String queryEdrewInfByMerId(HttpServletRequest request ,HttpServletResponse reponse ){
		logger.info("商户绑定银行卡信息接口");
		String merId = StringUtil.trim(request.getSession().getAttribute("merId").toString()); 
		Map<String , Object> resultMap = new HashMap<String ,Object>();
		//判断主商户号是否为空
		if(merId == null || merId.equals("")){
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取商户号失败!");
			logger.info("获取商户号失败!");
			return JSONObject.fromObject(resultMap).toString();
		}
		try {
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~调用查询商户绑定银行卡信息接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			com.umpay.operation.common.ReqMessage req = ReqMessageUtil.makeOpReq();
			Map<String, Object> reqMap = new HashMap<String, Object>();
			reqMap.put("merId", merId);
		    reqMap.put("delayDays", 1);
		    reqMap.put("state", "2");
//		    reqMap.put("recvBankAccPro", "0");
			req.setReqMap(reqMap);
			logger.info("查询商户绑定银行卡信息接口入参：" + req);
			com.umpay.operation.common.ResMessage res = edrawInfRemote.queryEdrewInf(req);
			logger.info("查询商户绑定银行卡信息接口出参：" + res);
			if(!res.getRetCode().equals(RetCode.SUCCESS)){			//查询失败
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "查询商户绑卡信息失败!");
				logger.info("调用查询商户绑卡信息接口失败!");
				return JSONObject.fromObject(resultMap).toString();
			} 
			EdrawInf edrawInfReData =(EdrawInf) res.getResMap().get("edrawInf");
			if( edrawInfReData == null || edrawInfReData.equals("") ){		//查询无数据
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "查询商户绑卡信息为空!");
				logger.info("调用查询商户绑卡信息接口无数据!merId："+merId);
				return JSONObject.fromObject(resultMap).toString();
			}
			resultMap.put("retCode", RetCode.SUCCESS);
			resultMap.put("retMsg", "查询商户绑卡信息成功!");
			Map<String, Object> resMap = new HashMap<String, Object>();
			resMap.put("bankName",StringUtil.trim(edrawInfReData.getBankName()));
			resMap.put("bankAccount",StringUtil.trim(edrawInfReData.getBankAccount()));
			resMap.put("binBankId", StringUtil.trim(edrawInfReData.getBinBankId()));
			resMap.put("merId", merId);
			resMap.put("colAccName", StringUtil.trim(edrawInfReData.getColAccName()));
			resMap.put("state", StringUtil.trim(edrawInfReData.getState()));
			resMap.put("recvBankAccPro", edrawInfReData.getRecvBankAccPro());
			resultMap.put("EdrawInfReData", resMap);
			logger.info("查询商户绑定的银行卡信息成功！");
			return JSONObject.fromObject(resultMap).toString();
		} catch (Exception e) {
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "查询商户绑卡信息失败!");
			logger.info("调用查询商户绑卡信息接口失败!");
		}
		return JSONObject.fromObject(resultMap).toString();
	}
	
	
	/**
	 * 下发验证码短信接口
	 * @param request
	 * @param reponse
	 * @param bankMobileId
	 * @return
	 */
	@RequestMapping(value = "/send", produces = "text/html;charset=UTF-8")
	@ResponseBody
	public String send(HttpServletRequest request, HttpServletResponse reponse,String bankMobileId) {
		logger.info("调用下发短信验证码接口");
		HttpSession session = request.getSession();
		Map<String, Object> resultMap = new HashMap<String, Object>();

		if (bankMobileId == null || bankMobileId.equals("")) { // 校验手机号是否为空
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取手机号失败!");
			logger.info("获取手机号失败!");
			return JSONObject.fromObject(resultMap).toString();
		}
		try {
			// ~~~~~~~~~~~~~~~~~~~~~~~~~调用下发短信息验证码接口~~~~~~~~~~~~~~~~~~~~~~~~~
			String productId = "SPAPPLY1";
			logger.info("下发短信验证码接口入参" + "bankMobileId:" + bankMobileId + "productId" + productId);
			Map<String, String> res = SmsCheckUtil.send(bankMobileId, productId);
			logger.info("下发短信验证码接口出参：" + res);
			if (res == null || res.equals("")) { // 调用失败
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "下发短信验证码失败!");
				logger.info("下发短信验证码失败!");
				return JSONObject.fromObject(resultMap).toString();
			}
			if (!res.get("retCode").equals(RetCode.SUCCESS)) { // 错误
				resultMap.put("retCode", StringUtil.trim(res.get("retCode")));
				resultMap.put("retMsg", StringUtil.trim(res.get("retMsg")));
				logger.info("下发短信验证码错误!");
				return JSONObject.fromObject(resultMap).toString();
			}
			session.setAttribute("smsVerifyTrace",StringUtil.trim(res.get("smsVerifyTrace")));
			session.setAttribute("verifyCode",StringUtil.trim(res.get("verifyCode")));
			session.setAttribute("mobileNo",StringUtil.trim(res.get("mobileNo")));
			resultMap.put("retCode", RetCode.SUCCESS);
			resultMap.put("retMsg", "下发短信验证码信息成功!");
			resultMap.put("bankMobileId", bankMobileId); // 手机号
			resultMap.put("trace", StringUtil.trim(res.get("smsVerifyTrace"))); // 流水号
			resultMap.put("verifyCode", StringUtil.trim(res.get("verifyCode")));
			logger.info("下发短信验证码成功！");
			return JSONObject.fromObject(resultMap).toString();
		} catch (Exception e) {
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "下发短信验证码失败!");
			logger.info("下发短信验证码失败!");
		}
		return JSONObject.fromObject(resultMap).toString();
	}
	
	
	/**
	 * 校验验证码，校验银行卡并绑定接口 
	 * @param request
	 * @param reponse
	 * @param bankAccount
	 * @return
	 */
 	@RequestMapping(value="/checkBinding" , method = {RequestMethod.POST,RequestMethod.GET },produces="text/html;charset=UTF-8")
	@ResponseBody
	public String checkBinding(HttpServletRequest request ,HttpServletResponse reponse ,String bankAccount,
		   String bankMobileId,String code,String binBankId,String bankName){
		logger.info("校验并绑定接口！");
		HttpSession session=request.getSession();
		Map<String, Object> resultMap = new HashMap<String , Object>();
		if(session==null || session.getAttribute("merId") == null){
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取session数据失败!");
			logger.info("获取session数据失败！");
			return  JSONObject.fromObject(resultMap).toString();
		}
		String merId = StringUtil.trim(session.getAttribute("merId").toString());
		logger.info("session获取商户号merId:"+ merId);
		String payeeName = session.getAttribute("payeeName").toString();
		String payeeInidcardS = session.getAttribute("payeeInidcard").toString();
		//校验银行卡号是否为空
		if(bankAccount == null || bankAccount.equals("")){
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取银行卡号失败!");
			logger.info("获取前台银行卡号失败！");
			return  JSONObject.fromObject(resultMap).toString();
		}
		logger.info("调用校验验证码信息接口，校验短信验证码！");
		String mobileNo=bankMobileId;
		String verifyCode= code;
		String smsVerifyTrace=StringUtil.trim(session.getAttribute("smsVerifyTrace"));	//从session中获取流水号
		if(mobileNo == null || mobileNo.equals("")){
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取手机号失败!");
			logger.info("获取前台手机号失败！");
			return  JSONObject.fromObject(resultMap).toString();
		}
		if(verifyCode == null || verifyCode.equals("")){
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取验证码失败!");
			logger.info("获取验证码失败！");
			return  JSONObject.fromObject(resultMap).toString();
		}
		if(smsVerifyTrace == null || smsVerifyTrace.equals("")){
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取流水号失败!");
			logger.info("获取流水号失败！");
			return  JSONObject.fromObject(resultMap).toString();
		}
		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~检验短信验证码接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		logger.info("校验短信验证码接口入参：" + "mobileNo:" + mobileNo + "smsVerifyTrace:" + smsVerifyTrace + "verifyCode:" + verifyCode);
		Map<String,String> res=SmsCheckUtil.checksms(mobileNo, smsVerifyTrace, verifyCode);
		logger.info("校验短信验证码接口出参：" + res);
		if(res==null || res.equals("")){	//失败
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "校验验证码失败!");
			logger.info("校验验证码失败！");
			return  JSONObject.fromObject(resultMap).toString();
		}
		if(!res.get("retCode").equals(RetCode.SUCCESS)){		//验证码错误
			resultMap.put("retCode", StringUtil.trim(res.get("retCode")));
			resultMap.put("retMsg", StringUtil.trim(res.get("retMsg")));
			logger.info("验证码错误！");
			return  JSONObject.fromObject(resultMap).toString();
		}
		//成功进行四要素鉴权，检验银行卡
		logger.info("校验验证码成功！");
		String desKey = StringUtil.trim(PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties", "des.secureKey","KSagZxG3"));
		DesUtil desUtil = new DesUtil(desKey);
		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~公共鉴权(姓名、身份证号码、手机号、银行卡号)~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		logger.info("调用公共鉴权接口校验银行卡信息！");
		ReqMessage req = ReqMessageUtil.makeSpReq(); 
		String bankAccountS = desUtil.enc_des(bankAccount);	  //加密银行卡号
		String url = PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties","id.auth");
		Map<String, Object> param  = new HashMap<String, Object>();
		param.put("rpid", RandomUtil.getRandom(0, 10));
		param.put("reqDate", StringUtil.trim(req.getReqDate()));
		param.put("reqTime", StringUtil.trim(req.getReqTime()));
		//商户号传联动内部固定的商户号  给用户鉴权
		String  jQmerId = PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties", "jQmerId");
		param.put("merId",jQmerId);
		param.put("productId", "P15Y0002");		//产品号传了立马付中的任意一个
		param.put("busiMerId", jQmerId);
		param.put("bankAccount", StringUtil.trim(bankAccountS));
		param.put("accountName", payeeName);
		param.put("bankIdentityType", "1");
		param.put("bankIdentityCode", payeeInidcardS);	//证件号密文
		param.put("bankMobileId", StringUtil.trim(bankMobileId));
		param.put("strictVeriFlag", "1");	//借记卡四要素强校验标识
		Map<String, Object> map = null ;
		if(merId == null || merId.equals("")){
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取商户号失败!");
			logger.info("从session中获取商户号失败！");
			return  JSONObject.fromObject(resultMap).toString();
		}
		if(bankAccountS == null || bankAccountS.equals("")){
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "加密银行卡号失败!");
			logger.info("加密银行卡号失败！");
			return  JSONObject.fromObject(resultMap).toString();
		}
		if(payeeName == null || payeeName.equals("")){
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取收款人姓名失败!");
			logger.info("从session中获取收款人姓名失败！");
			return  JSONObject.fromObject(resultMap).toString();
		}
		try {
			logger.info("公共鉴权请求url：" + url);
			logger.info("公共鉴权接口入参：" + param);
			map = HttpUtil.httpPostForm2Xml(url, param,"utf-8");
			logger.info("公共鉴权接口出参：" + map);
		} catch (Exception e) {
			e.printStackTrace();
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "公鉴权失败!");
			logger.info("公共鉴权名失败！");
			return  JSONObject.fromObject(resultMap).toString();
		} 
		if(map == null || map.equals("")){		//查询失败
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", map.get("retMsg").toString());
			logger.info("公共鉴权失败！");
			return  JSONObject.fromObject(resultMap).toString();
		}
		if( !map.get("retCode").equals(RetCode.SUCCESS)){		//错误
			resultMap.put("retCode", map.get("retCode").toString());
			resultMap.put("retMsg", map.get("retMsg").toString());
			resultMap.put("rpid", map.get("rpid").toString());
			logger.info("公共鉴权未通过！" + map);
			return  JSONObject.fromObject(resultMap).toString();
		}
		//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~查询绑定银行卡信息（判断是绑卡还是换卡）~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		logger.info("银行卡四要素校验通过！");
		logger.info("查询商户绑定银行卡接口：merId"+merId);
		com.umpay.operation.common.ReqMessage reqM = ReqMessageUtil.makeOpReq();
	    Map<String, Object> reqMap = new HashMap<String, Object>();
	    reqMap.put("merId", merId);
	    reqMap.put("delayDays", 1);	//推迟提现时间
	    reqMap.put("state", "2");	//状态  可用2
//	    reqMap.put("recvBankAccPro", "0");	//个人账户0
	    reqM.setReqMap(reqMap);
		com.umpay.operation.common.ResMessage ress;
		try {
			logger.info("查询商户绑定银行卡接口入参："+reqM);
			ress = edrawInfRemote.queryEdrewInf(reqM);
			logger.info("查询商户绑定银行卡接口出参："+ress);
		} catch (Exception e1) {
			e1.printStackTrace();
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "查询绑定银行卡信息接口失败!");
			logger.info( "查询绑定银行卡信息接口失败!");
			return  JSONObject.fromObject(resultMap).toString();
		}
		if(ress == null || !ress.getRetCode().equals(RetCode.SUCCESS)){   //查询失败
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "查询绑定银行卡信息接口失败!");
			logger.info( "查询绑定银行卡信息接口失败!");
			return  JSONObject.fromObject(resultMap).toString();
		}
		//判断是否有绑卡信息
		EdrawInf edrawInfReData = (EdrawInf) ress.getResMap().get("edrawInf");
		if(edrawInfReData !=null && !edrawInfReData.equals("")){	//已经绑卡，更换银行卡
			logger.info("判断绑卡成功商户已绑卡merId："+merId);
			//~~~~~~~~~~~~~~~~~~~~~~~~~判断此用户是对公还是对私账户~~~~~~~~~~~~~~~~~~~~~~~~~~
			logger.info("判断此用户是对公还是对私账户");
			Short recvBankAccPro = edrawInfReData.getRecvBankAccPro();
			logger.info("商户类型0对私1对公:" + recvBankAccPro);
			if(1 == recvBankAccPro){
				logger.info("商户类型为对公账户");
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "暂不支持自助更换对公结算银行卡!");
				return  JSONObject.fromObject(resultMap).toString();
			}
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			logger.info("更换银行卡merId："+merId);
			//校验卡号是否与原银行卡号重复
			if( edrawInfReData.getBankAccount() != null && edrawInfReData.getBankAccount().equals(bankAccount)){
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "卡号与原卡号相同!");
				logger.info( "卡号与原卡号相同!");
				return  JSONObject.fromObject(resultMap).toString();
			}
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~调用更换绑定银行卡接口~~~~~~~~~~~~~~~~~~~~~~~
			com.umpay.operation.common.ReqMessage reqMess = ReqMessageUtil.makeOpReq();
			Map<String, Object> cardMap = new HashMap<String,Object>();
			cardMap.put("merId", merId);
			cardMap.put("binBankId", binBankId);
			cardMap.put("bankName", bankName);
			cardMap.put("bankAccount", bankAccount);
			cardMap.put("colAccName", payeeName);
			cardMap.put("delayDays", "1");	//推迟提现时间
			cardMap.put("merId", merId);
			cardMap.put("state", "2");		//状态2可用
			cardMap.put("recvBankAccPro", "0");		//账号属性0个人
			reqMess.setReqMap(cardMap);
			com.umpay.operation.common.ResMessage ressM = null;
			try {
				logger.info("更换银行卡接口入参："+reqMess);
				ressM = edrawInfRemote.editEdrawInf(reqMess);
				logger.info("更换银行卡接口出参："+ressM);
			} catch (Exception e) {
				e.printStackTrace();
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "更换绑定的银行卡失败！");
				logger.info("更换绑定的银行卡失败！");
				return JSONObject.fromObject(resultMap).toString();
			}
			if(ressM == null || ressM.equals("")){
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "更换绑定的银行卡失败！");
				logger.info("更换绑定的银行卡失败！");
				return JSONObject.fromObject(resultMap).toString();
			}
			if(ressM.getRetCode() == null || !ressM.getRetCode().equals(RetCode.SUCCESS)){
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "更换绑定的银行卡失败！");
				logger.info("更换绑定的银行卡失败！");
				return JSONObject.fromObject(resultMap).toString();
			}
			//成功
			try {
				//--------------------微信推送更换绑定银行卡消息---------------------------
				String openId =StringUtil.trim(request.getSession().getAttribute("openid").toString());
				logger.info("session中获取到openid:" + openId); 
				//更换银行卡时间
				Date date=new Date();
				DateFormat format=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				String time=format.format(date);
				//银行卡后四位
				String str = bankAccount.substring(bankAccount.length()-4,bankAccount.length());
				String templateId1 = PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties","saas.wx.templateId1");
				Map<String,String> map1= new HashMap<String,String>();
				map1.put("template_id",templateId1);
				map1.put("openid",openId);
				map1.put("keyword1",bankName);//银行名称
				map1.put("keyword2",str);//银行卡后四位
				map1.put("keyword3",time);//操作时间
				boolean b = weixinService.sendTemplateMessage1(map1);
				if(!b){
					logger.info("更换银行卡发送微信模板消息失败！");
				}
				logger.info("更换银行卡发送微信模板消息成功！");
				//------------------给手机号发送更换银行卡的通知的短信消息-----------------------
				String productId = "SPAPPLY1";		
				Map<String , String > mapDx = new HashMap<String ,String >();
				mapDx.put("bankName", bankName);
				mapDx.put("str", str);
				mapDx.put("time", time);
				logger.info("发送模板消息接口入参：" + "手机号：" + mobileNo + "productId："+ productId +"mapDx：" + mapDx);
				Map<String, String> apDxx  = SmsCheckUtil.send(mobileNo, productId, mapDx);
				logger.info("发送模板消息接口出参：" + apDxx);
				if( !apDxx.get("retCode").equals(RetCode.SUCCESS)){
					logger.info("更换银行卡发送短信模板消息失败！");
				}
				logger.info("更换银行卡发送短信模板消息成功！");
			} catch (Exception e) {
				e.printStackTrace();
				logger.info("exception:" + e); 
				logger.info("更换银行卡推送消息失败！");
			}
			resultMap.put("retCode", RetCode.SUCCESS);
			resultMap.put("retMsg", "更换商户绑定银行卡成功！!");
			logger.info("绑定银行卡成功！merId："+merId);
			
			//-----------------绑完卡后，将银行预留手机号入库-----------------ChenFuLong 201709 SAAS基金需求
			updateBankMobileId(merId, mobileNo);
			
			return JSONObject.fromObject(resultMap).toString();
		}			
		//未绑卡 给用户添加银行卡
		logger.info("判断绑卡成功商户未绑卡merId："+merId);
		com.umpay.operation.common.ReqMessage reqMess = ReqMessageUtil.makeOpReq();
		Map<String, Object> cardMap = new HashMap<String,Object>();
		cardMap.put("merId", merId);
		cardMap.put("binBankId", binBankId);
		cardMap.put("bankName", bankName);
		cardMap.put("bankAccount", bankAccount);
		cardMap.put("colAccName", payeeName);
		cardMap.put("delayDays", "1");	//推迟提现时间
		cardMap.put("merId", merId);
		cardMap.put("state", "2");		//状态2可用
		cardMap.put("recvBankAccPro", "0");		//账号属性0个人
		reqMess.setReqMap(cardMap);
		//~~~~~~~~~~~~~~~~~~~~~~~~~~~调用绑定银行卡接口~~~~~~~~~~~~~~~~~~~~~~~~~
		com.umpay.operation.common.ResMessage resMess;
		try {
			logger.info("绑定银行卡接口入参："+ reqMess);
			resMess = edrawInfRemote.saveEdrewInf(reqMess);
			logger.info("绑定银行卡接口出参："+ resMess);
		} catch (Exception e) {
			e.printStackTrace();
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "查询绑定银行卡信息接口失败!");
			logger.info( "调用绑定银行卡失败息接口失败!merId："+merId);
			return  JSONObject.fromObject(resultMap).toString();
		}
		if(resMess == null || resMess.equals("")){		//失败
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "查询绑定银行卡信息接口失败!");
			logger.info( "调用绑定银行卡失败息接口失败!merId："+merId);
			return  JSONObject.fromObject(resultMap).toString();
		}
		if(resMess.getRetCode() == null || !resMess.getRetCode().equals(RetCode.SUCCESS) ){		//错误
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "绑定银行卡失败!");
			logger.info( "绑定银行卡失败！merId："+merId);
			return  JSONObject.fromObject(resultMap).toString();
		}
			resultMap.put("retCode", RetCode.SUCCESS);
			resultMap.put("retMsg", "绑定银行卡成功！!");
			logger.info("绑定银行卡成功！merId："+merId);
			
			//-----------------绑完卡后，将银行预留手机号入库-----------------ChenFuLong 201709 SAAS基金需求
			updateBankMobileId(merId, mobileNo);
			
			return JSONObject.fromObject(resultMap).toString();
	}
 	
 	/**
 	 * 更新银行预留手机号
 	 * @param storeId店铺编号（用主商户号）
 	 * @param bankMobileId银行预留手机号
 	 * @return
 	 */
 	public void updateBankMobileId(String storeId, String bankMobileId){
 		logger.info("【更新银行预留手机号】店铺编号：" + storeId + "，手机号" + bankMobileId);
 		ReqMessage reqStoreInf = ReqMessageUtil.makeSpReq();
		ResMessage resStoreInf = null;
		reqStoreInf.put("storeId",storeId);	//店铺编号
		try {
			logger.info("----#---------#--获取店铺部署详情，请求参数：--#---------#--" + reqStoreInf);
			resStoreInf = storeInfServiceRemote.getStoreInfByPri(reqStoreInf);
			logger.info("----#---------#--获取店铺部署详情，返回参数：--#---------#--" + resStoreInf);
		} catch (Exception e) {
			logger.error("----#---------#--获取店铺部署详情异常--#---------#--" + e);
		}
		if("0000".equals(resStoreInf.getRetCode())){	//查询店铺详情失败或异常
			StoreInf storeInf = (StoreInf) resStoreInf.getResMap().get("storeInf");
			storeInf.setPrestorePhone(bankMobileId);
			storeInf.setIntime(null);
			storeInf.setModtime(null);
			try {
				Map<String, String> storeMap = SaasPropertyUtil.javaBeanToMap(storeInf);
				ReqMessage req = ReqMessageUtil.makeSpReq();
				ResMessage res = null;
				req.putAll(storeMap);
				logger.info("----#---------#--更新店铺信息，请求参数：--#---------#--" + req);
				res = storeInfServiceRemote.updateStoreInf(req);
				logger.info("----#---------#--更新店铺信息，返回参数：--#---------#--" + res);
			} catch (Exception e) {
				logger.error("----#---------#--更新店铺信息异常--#---------#--" + e);
			}
		}
 	}
 	
 	
 	/**
 	 * 收入结算列表接口
 	 * @param requset
 	 * @param response
 	 * @return
 	 */
 	@RequestMapping(value="/presentation",method = {RequestMethod.POST,RequestMethod.GET },produces="text/html;charset=UTF-8")
 	@ResponseBody
 	public String presentation(HttpServletRequest request ,HttpServletResponse response,String storeId,String pageSize,String currentPage){
 		HttpSession session = request.getSession();
 		Map<String, Object> resultMap = new HashMap<String, Object>();
 		if(session == null || session.getAttribute("merId").equals("")){
 			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取session信息失败!");
			logger.info("获取session信息失败!");
			return JSONObject.fromObject(resultMap).toString();
 		}
	    String merId = StringUtil.trim(session.getAttribute("merId").toString());
 		try {
			logger.info("查询接算列表接口");
			//查询结算列表接口   查询出当前日期 12个自然月的月结算统计     
			Map<String,Object> qryMap = new HashMap<String,Object>();
			if(merId == null || merId.equals("")){
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "获取商户号失败！");
				logger.info("获取商户号！");
				return JSONObject.fromObject(resultMap).toString();
			}
			if(storeId == null || storeId.equals("")){
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "未获取都店铺编号！");
				logger.info("未获取都店铺编号！");
				return JSONObject.fromObject(resultMap).toString();
			}
			qryMap.put("merId", StringUtil.trim(storeId));	//结算以店铺号查询
			Calendar calendar = Calendar.getInstance();
			Date date = calendar.getTime();		
			String endDateStr = DateTimesUtil.date8(date);		//当前日期
			calendar.add(Calendar.YEAR, -1);	//开始时间为当前时间的前12自然月日期       结束时间为当前日期
			calendar.add(Calendar.MONTH, 1);
			calendar.set(Calendar.DATE, 1);
			String startDateStr = DateTimesUtil.date8(calendar.getTime());	//12自然月日期
			
			qryMap.put("startDate", startDateStr);		//YYYYMMdd
			qryMap.put("endDate", endDateStr);		//YYYYMMdd
			qryMap.put("dealState", "2");		//处理状态    完成2
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~调用结算查询接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			logger.info("结算查询接口入参：" + qryMap);
			List<SettleStat> settleStatList = settleStatServiceRemote.querySettleStats(qryMap);
			logger.info("结算查询接口出参：" + settleStatList);
			//验查询结算信息返回结果
			if(settleStatList == null || settleStatList.size() == 0){
				resultMap.put("retCode", RetCode.SUCCESS);
				resultMap.put("retMsg", "此店铺无结算数据！");
				logger.info("结算列表无数据！");
				return JSONObject.fromObject(resultMap).toString();
			}
			//按月统计  放进newSettleStatList中
			List<SettleStat> newSettleStatList = new ArrayList<SettleStat>();
			for(SettleStat settleStat : settleStatList){
//				settleStat.setSettleDate(addDays(settleStat.getSettleDate(), -1));//结算日期-1 --->收入日期
				boolean isOld = false;
				String settleStatYm = settleStat.getSettleDate().substring(0,6);
				for(SettleStat newSettleStat : newSettleStatList){
					//相同年月
					if(settleStatYm.equals(newSettleStat.getSettleDate().substring(0,6))){
//						Long amount = settleStat.getAmount();	//结算金额
						Long amount = settleStat.getAmount() - settleStat.getComAmt();	//结算金额－手续费
						newSettleStat.setAmount(newSettleStat.getAmount() + amount);
						isOld = true;
					}
				}
				if(!isOld){
					Long amount = settleStat.getAmount() - settleStat.getComAmt();
					settleStat.setAmount(amount);
					newSettleStatList.add(settleStat);
				}
			}
			//编辑输出列表
			List<Map<String,Object>> resultList = new ArrayList<Map<String,Object>>();
			for(SettleStat settleStat : newSettleStatList){
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("month", settleStat.getSettleDate().substring(0,6));
				map.put("amount", AmountUtil.Cent2Dollar2(settleStat.getAmount()));//分转元
				resultList.add(map);
			}
			logger.info("结算列表初始化成功！");
			resultMap.put("retCode", RetCode.SUCCESS);
			resultMap.put("retMsg", "结算列表初始化成功！");
			resultMap.put("total", resultList);
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~调用分页查询结算列表接口  查询出第一页数据~~~~~~~~~~~~~~~~~~~~~~~
			String  ress = this.querySettlePage(request, response,storeId,1,20);
			String a = JSONObject.fromObject(ress).get("retCode").toString(); 
			if( !a.equals(RetCode.SUCCESS)){
				logger.info("查询提现信息失败！");
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "查询结算列表失败！");
		 		return JSONObject.fromObject(resultMap).toString();
			}
			JSONObject.fromObject(ress).get("listDay"); 
			resultMap.put("listDay", JSONObject.fromObject(ress).get("listDay"));
			return JSONObject.fromObject(resultMap).toString(); 
		} catch (Exception e) {
			System.err.print(e);
			logger.info("查询结算信息失败");
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "查询结算信息失败");
		}
 		return JSONObject.fromObject(resultMap).toString();
 	}
 	
 	
	 /**
	  * 结算列表分页查询接口
	  * @param request
	  * @param response
	  * @param currentPage
	  * @param pageSize
	  * @return
	  */
 	@RequestMapping(value="querySettlePage",method = {RequestMethod.POST,RequestMethod.GET },produces="text/html;charset=UTF-8")
 	@ResponseBody
 	public String querySettlePage(HttpServletRequest request ,HttpServletResponse response,String storeId ,int currentPage, int pageSize){
 		HttpSession session = request.getSession();
 		Map<String, Object> resultMap = new HashMap<String, Object>();
 		if(session == null || session.getAttribute("merId").toString().equals("")){
 			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取session信息失败!");
			logger.info("获取session信息失败!");
			return JSONObject.fromObject(resultMap).toString();
 		}
 		String merId = StringUtil.trim(session.getAttribute("merId").toString());
 		logger.info("结算列表分页查询接口");
 		if(storeId == null || storeId.equals("")){			
 			logger.info("页大小或者页码为0！");
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "页大小或者页码为0");
			return JSONObject.fromObject(resultMap).toString();
 		}
 		if(pageSize == 0 || currentPage == 0){			
 			logger.info("页大小或者页码为0！");
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "页大小或者页码为0！");
			return JSONObject.fromObject(resultMap).toString();
 		}
 		try {
 			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~调用结算查询（分页）接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			logger.info("调用结算查询（分页）接口");
			Map<String, Object> qryMap = new HashMap<String, Object>();
			Calendar calendar = Calendar.getInstance();
			Date date = calendar.getTime();		
			String endDateStr = DateTimesUtil.date8(date);		//当前日期
			calendar.add(Calendar.YEAR, -1);	//开始时间为当前时间的前12自然月日期       结束时间为当前日期
			calendar.add(Calendar.MONTH, 1);
			calendar.set(Calendar.DATE, 1);
			String startDateStr = DateTimesUtil.date8(calendar.getTime());	//12自然月日期
			qryMap.put("merId",storeId);
			qryMap.put("startDate", startDateStr);		//YYYYMMdd
			qryMap.put("endDate", endDateStr);		//YYYYMMdd     
			qryMap.put("dealState", "2");
			logger.info("调用结算查询（分页）接口入参" + qryMap + "currentPage:" + currentPage +"pageSize:"+ pageSize);
			List<SettleStat> settleStatList = settleStatServiceRemote.querySettleStats(qryMap,currentPage,pageSize);
			logger.info("调用结算查询（分页）接口出参" + settleStatList);
			//校验查询结算信息返回结果
			if(settleStatList == null || settleStatList.equals("") || settleStatList.size() == 0){
				logger.info("结算列表无数据！");
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "结算列表无数据！");
				return JSONObject.fromObject(resultMap).toString();
			}
			//遍历20条   以每条的日期为准查询提现记录
			List<String> listDay = new ArrayList<String>();
			for(SettleStat newSettleStat : settleStatList){
				SettleList settleList = new SettleList();//存放结算、付款数据
				//结算日期
				String settleStatYm = StringUtil.trim(newSettleStat.getSettleDate());
				Calendar c1 = new GregorianCalendar();
				SimpleDateFormat d1 = new SimpleDateFormat("yyyyMMdd");
				Date date1 = d1.parse(StringUtil.trim(settleStatYm));
				c1.setTime(date1);
//				c1.add(Calendar.DATE,-1);
				String inDateStr=DateTimesUtil.date8(c1.getTime());//收入日期
				Calendar c2 = new GregorianCalendar();
				c2.setTime(date1);
				c2.add(Calendar.MONTH,3);
				String startStr = DateTimesUtil.date8(date1);// 提现查询开始日期：结算日期
				String endStr = "";//提现查询结束日期：结算日期+3月
				Calendar c3 = new GregorianCalendar();
				if(c2.compareTo(c3) == -1 || c2.compareTo(c3) == 0){    //结束日期比当前日期小
					 endStr = DateTimesUtil.date8(c2.getTime());
				}
				if(c2.compareTo(c3) == 1){
					 endStr = DateTimesUtil.date8(c3.getTime());
				}
					//根据结算日期查询付款提现信息
					//优先从redis中取
//					String redisKey = "settlement"+storeId+inDateStr;
					String redisKey = CacheConsts.WX + CacheConsts.SETTLEMENT + storeId + inDateStr;
					String settleListRedis = RedisUtil.get(redisKey);
					//缓存中没有
					if(settleListRedis == null || settleListRedis.isEmpty() || settleListRedis.equals("")){
						//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~调用收入提现接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
						logger.info("调用付款查询（提现）接口");
						ReqMessage reqMessage = ReqMessageUtil.makeSpReq();
						Map<String, String> reqMap = new HashMap<String, String>();
						reqMap.put("merId", merId);
						reqMap.put("endDate", endStr);
						reqMap.put("startDate", startStr);
						reqMap.put("currentPage", "1");
						reqMap.put("pageSize", "10000");
						reqMessage.setReqMap(reqMap);
						logger.info("入参" + reqMessage);
						ResMessage resMess = revPayOrderServiceRemote.queryRevPayOrdersForPage(reqMessage);
						logger.info("出参" + resMess);
						if(resMess.getRetCode() == null || !resMess.getRetCode().equals(RetCode.SUCCESS) ){
							logger.info("付款查询失败！");
							resultMap.put("retCode", RetCode.FAIL);
							resultMap.put("retMsg", "付款查询失败！");
							return JSONObject.fromObject(resultMap).toString();
						}
						List<RevPayOrder>  revPayOrderList = (List<RevPayOrder>) resMess.getResMap().get("resultList");
						//条件查询的没有付款信息-----没有提现
						if(revPayOrderList == null || revPayOrderList.equals("") || revPayOrderList.size() == 0){
							settleList.setTixiandate("");//提现日期
							settleList.setDate(inDateStr);//收入日期
							String amt = AmountUtil.Cent2Dollar2(newSettleStat.getAmount() - newSettleStat.getComAmt());//净结算金额      分转元
							settleList.setAmt(amt);
							settleList.setKahao("");//收款方银行账号(提现记录中获取银行卡号 inMediaId)
							settleList.setBankName("");//银行名称
//							listDay.add(settleList);
							settleListRedis = JSONObject.fromObject(settleList).toString();
						}
						//将符合匹配条件的结算和付款   放进一个settleList对象中返回
						if(revPayOrderList != null && revPayOrderList.size() != 0){
							RevPayOrder revPayOrder =revPayOrderList.get(revPayOrderList.size()-1);
							String revPayOrderDate = DateTimesUtil.date8(revPayOrder.getInTime());
							settleList.setTixiandate(revPayOrderDate);//提现日期
							settleList.setDate(inDateStr);//收入日期
							String amt = AmountUtil.Cent2Dollar2(newSettleStat.getAmount() - newSettleStat.getComAmt());//结算金额      分转元
							settleList.setAmt(amt);
							settleList.setKahao(revPayOrder.getInMediaId());//收款方银行账号(提现记录中获取银行卡号 inMediaId)
							settleList.setBankName(revPayOrder.getBankName());//银行名称
//							listDay.add(settleList);
							settleListRedis = JSONObject.fromObject(settleList).toString();
							//=====================将查询出的结果放到redis中==================================
							RedisUtil.set(redisKey, seconds, settleListRedis);
						} 
					}
					listDay.add(settleListRedis);
			}
			logger.info("查询结算列表成功！");
			resultMap.put("retCode", RetCode.SUCCESS);
			resultMap.put("retMsg", "查询结算列表成功！");
			resultMap.put("listDay", listDay);
			resultMap.put("currentPage", currentPage);
			return JSONObject.fromObject(resultMap).toString();
		} catch (Exception e) {
			logger.info("调用结算查询（分页）接口失败！");
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "调用结算查询（分页）接口失败！");
		}
 		return JSONObject.fromObject(resultMap).toString();
 	}
 	
 	/**
 	 * 更换银行卡接口
 	 * @param request
 	 * @param response
 	 * @param colAccName
 	 * @param payeeInidcard
 	 * @param bankMobileId
 	 * @param code
 	 * @return
 	 */
 	@RequestMapping(value="/changeCard",method = {RequestMethod.POST,RequestMethod.GET },produces="text/html;charset=UTF-8")
 	@ResponseBody
 	public String changeCard(HttpServletRequest request,HttpServletResponse response,String colAccName,
 		String payeeInidcard,String bankMobileId,String code ){
 		logger.info("更换商户绑定的银行卡");
 		Map<String , Object> resultMap = new HashMap<String ,Object>();
 		if(colAccName == null || colAccName.equals("") || payeeInidcard == null ||
 			payeeInidcard.equals("") || bankMobileId == null || bankMobileId.equals("") || code == null || code.equals("")){
 			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取前台数据失败！");
			logger.info("获取前台数据失败！");
			return JSONObject.fromObject(resultMap).toString();
 		}
 		HttpSession session = request.getSession();
 		if(session == null || session.getAttribute("merId").equals("")){
 			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "获取session信息失败!");
			logger.info("获取session信息失败!");
			return JSONObject.fromObject(resultMap).toString();
 		}
 		String merId = StringUtil.trim(session.getAttribute("merId").toString());
 		String smsVerifyTrace=StringUtil.trim(session.getAttribute("smsVerifyTrace"));	//从session中获取流水号
 		try {
			//~~~~~~~~~~~~~~~~~~~~~~~~~校验短信验证码接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			Map<String,String> res=SmsCheckUtil.checksms(bankMobileId, smsVerifyTrace, code);
			if(res == null || res.equals("")){		//失败
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "校验短信验证码失败！");
				logger.info("校验短信验证码失败！");
				return JSONObject.fromObject(resultMap).toString();
			}
			if(res.get("retCode") == null || !res.get("retCode").equals(RetCode.SUCCESS)){	//错误		
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", res.get("retMsg"));
				logger.info("校验短信验证码失败！");
				return JSONObject.fromObject(resultMap).toString();
			}
			//成功
			logger.info("校验短信验证码成功！");
			//~~~~~~~~~~~~~~~~~~~~~~~~~查询银行卡信息接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			logger.info("查询商户绑定银行卡信息！");
			com.umpay.operation.common.ReqMessage req = ReqMessageUtil.makeOpReq();
			Map<String , Object> reqMap = new HashMap<String,Object>();
			reqMap.put("merId", merId);
		    reqMap.put("delayDays", 1);
		    reqMap.put("state", "2");
//		    reqMap.put("recvBankAccPro", "0");
		    req.setReqMap(reqMap);
		    logger.info("【查询商户绑定银行卡信息接口】入参：" + req);
			com.umpay.operation.common.ResMessage resM = edrawInfRemote.queryEdrewInf(req);
			logger.info("【查询商户绑定银行卡信息接口】出参：" + resM);
			if(resM == null || resM.equals("")){
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "查询银行卡信息接口失败！");
				logger.info("查询银行卡信息接口失败！");
				return JSONObject.fromObject(resultMap).toString();
			}
			if(resM.getRetCode() == null || !resM.getRetCode().equals(RetCode.SUCCESS) ){
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "查询银行卡信息接口失败！");
				logger.info("查询银行卡信息接口失败！");
				return JSONObject.fromObject(resultMap).toString();

			}
			//成功
			logger.info("查询收商户绑卡信息成功！");
			//判断是否与绑卡信息一致    决定是否可以换卡
			EdrawInf edrawInfReData = (EdrawInf) resM.getResMap().get("edrawInf");
			//无绑卡信息
			if(edrawInfReData == null || edrawInfReData.equals("")){
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "查询商户绑卡信息无数据！");
				logger.info("查询商户绑卡信息无数据！");
				return JSONObject.fromObject(resultMap).toString();
			}
//			//~~~~~~~~~~~~~~~~~~~~~~~~判断对公对私 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//			logger.info("判断此用户是对公还是对私账户");
//			Short recvBankAccPro = edrawInfReData.getRecvBankAccPro();
//			logger.info("商户类型0对私1对公:" + recvBankAccPro);
//			if(1 == recvBankAccPro){
//				logger.info("商户类型为对公账户");
//				resultMap.put("retCode", RetCode.FAIL);
//				resultMap.put("retMsg", "暂不支持自助更换对公结算银行卡!");
//				return  JSONObject.fromObject(resultMap).toString();
//			}
			//有绑卡信息
			ReqMessage reqm = ReqMessageUtil.makeSpReq();
			reqm.getReqMap().put("storeId", merId);
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~店铺部署详情信息接口，查询收款人信息~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			ResMessage resm = storeInfServiceRemote.getStoreInfByPri(reqm);
			if(!resm.getRetCode().equals(RetCode.SUCCESS)){	//查询失败
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "查询收款人信息接口失败!");
				logger.info("查询收款人信息失败merId："+merId);
				return JSONObject.fromObject(resultMap).toString();
			}
			com.umpay.sp.model.saas.StoreInf storeInfoo =  (com.umpay.sp.model.saas.StoreInf) resm.getResMap().get("storeInf");
			if(storeInfoo ==null ||storeInfoo.equals("")){		//无数据
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "查询收款人信息无数据!");
				logger.info("查询收款人信息无数据merId："+merId);
				return JSONObject.fromObject(resultMap).toString();
			}
			String payeeInidcardSS = storeInfoo.getPayeeInidcard();  //查出的收款人身份证号是密文
			if(payeeInidcardSS == null || payeeInidcardSS.equals("")){
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "查询收款人身份证号失败！");
				logger.info("查询收款人身份证号失败！");
				return JSONObject.fromObject(resultMap).toString();
			}
			//+++++++++++++++++++++换卡验证页面输入的手机号为收款人的手机号+++++++++++++++++++++++++++++++++++
			String payeeMobile = StringUtil.trim(storeInfoo.getPayeeMobileId());
			if(payeeMobile == null || payeeMobile.equals("")){
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "查询收款人手机号失败！");
				logger.info("查询收款人手机号失败！");
				return JSONObject.fromObject(resultMap).toString();			
			}
			//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
			//绑定的银行卡姓名
			String  name = edrawInfReData.getColAccName();
			String desKey = StringUtil.trim(PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties", "des.secureKey","KSagZxG3"));
			DesUtil desUtil = new DesUtil(desKey);
			String payeeNo = desUtil.dec_des(payeeInidcardSS);   //解密
			if(name == null || name.equals("")){
				resultMap.put("retCode", RetCode.FAIL);
				resultMap.put("retMsg", "商户绑卡姓名为空！");
				logger.info("商户绑卡姓名为空！");
				return JSONObject.fromObject(resultMap).toString();
			}
			logger.info("判断是否与绑定银行卡信息一致");
			logger.info("收款人手机号：" + payeeMobile + "输入手机号：" + bankMobileId);
			//与绑卡信息一致
			if(name != null && name.equals(colAccName) && payeeNo != null && payeeInidcard.equals(payeeNo) &&
					bankMobileId != null && bankMobileId.equals(payeeMobile)){
				logger.info("和绑定的银行卡信息一致！");
				resultMap.put("retCode", RetCode.SUCCESS);
				resultMap.put("retMsg", "与绑定银行卡信息一致，可以跳转添加银行卡页面！");
				logger.info("与绑定银行卡信息一致可以跳转添加银行卡页面！");
				return JSONObject.fromObject(resultMap).toString();
			}
			//与绑卡信息不一致
			logger.info("和绑定的银行卡信息不一致！");
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "与绑定银行卡信息不一致！");
			logger.info("与绑定银行卡信息不一致！");
			return JSONObject.fromObject(resultMap).toString();
		} catch (Exception e) {
			e.printStackTrace();
			resultMap.put("retCode", RetCode.FAIL);
			resultMap.put("retMsg", "更换银行卡失败！");
			logger.info("更换银行卡失败！");
		}
 		return JSONObject.fromObject(resultMap).toString();
 	}
 	
	/**
	 * 日期加减天数
	 * 
	 * @param dateStr 日期
	 * @param days 天数
	 * @return
	 */
	private String addDays(String dateStr, int days){
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.YEAR, Integer.parseInt(dateStr.substring(0, 4)));
		calendar.set(Calendar.MONTH, Integer.parseInt(dateStr.substring(4, 6))-1);
		calendar.set(Calendar.DATE, Integer.parseInt(dateStr.substring(6, 8)));
		calendar.add(Calendar.DATE, days);
        return DateTimesUtil.date8(calendar.getTime());
	}
}
